package com.kuang.web.admin;

import com.kuang.pojo.Logs;
import com.kuang.service.LogsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin")
public class LogsControoler {

    @Autowired
    private LogsService userIpService;

    @RequestMapping("tojournal")
    public String tojournal(Model model, @RequestParam(defaultValue = "1") Integer pageindex) {
        Integer pagesize = 100; // 每页显示100个
        Integer countuserip = userIpService.countUserIp();
        Integer page = countuserip % pagesize == 0 ? countuserip / pagesize : (countuserip / pagesize) + 1;
        List<Logs> userIpList = userIpService.selectUserIpPage(pagesize * (pageindex - 1), pagesize);
        model.addAttribute("logslist", userIpList);
        model.addAttribute("countuserip", countuserip);
        model.addAttribute("page", page);
        model.addAttribute("pageindex", pageindex);
        for (Logs logs : userIpList) {
            System.out.println("logs = " + logs);
        }
        return "admin/logs-mgr";
    }

    @RequestMapping("deleteuserip")
    @ResponseBody
    public String deleteuserip(Integer useripid) {
////        System.out.println("test = " + test);
//        System.out.println("useripid = " + useripid);
//        System.out.print  ln("testdeleteip");
        int i = userIpService.deleteUserIp(useripid);
        if (i > 0) {
            return "success";

        } else {
            return "error";
        }
    }
}
